﻿namespace WeightConverterNamespace
{
    public class WeightConverter
    {
        public WeightConverter() { }
        void ConvertWeightToPound(ref Weight weight)
        {
            switch (weight.Type)
            {
                case WeightType.kg:
                {
                    weight.Quantity = weight.Quantity / 0.454;
                    break;
                }
                case WeightType.pound:
                {
                    break;
                }
                case WeightType.ounce:
                {
                    weight.Quantity = weight.Quantity * 0.0625;
                    break;
                }
                case WeightType.grain:
                {
                    weight.Quantity = weight.Quantity * 0.0625 * 0.002286;
                    break;
                }
                case WeightType.dram:
                {
                    weight.Quantity = weight.Quantity * 0.0625 * 0.0625;
                    break;
                }
            }
            weight.Type = WeightType.pound;
        }
        void ConvertWeightFromPound(Weight knownWeight, ref Weight newWeight)
        {            
             switch (newWeight.Type)
             {
                case WeightType.kg:
                {
                    newWeight.Quantity = knownWeight.Quantity * 0.454;
                    break;
                }
                case WeightType.pound:
                {
                    newWeight.Quantity = knownWeight.Quantity;
                    break;
                }
                case WeightType.ounce:
                {
                    newWeight.Quantity = knownWeight.Quantity / 0.0625;
                    break;
                }
                case WeightType.grain:
                {
                    newWeight.Quantity = knownWeight.Quantity / (0.0625 * 0.002286);
                    break;
                }
                case WeightType.dram:
                {
                    newWeight.Quantity = knownWeight.Quantity / (0.0625 * 0.0625);
                    break;
                }
            }
        }
        public void Convert(Weight knownWeight, ref Weight newWeight)
        {
            ConvertWeightToPound(ref knownWeight);
            ConvertWeightFromPound(knownWeight, ref newWeight);           
        }
    }
}
